module.exports = {
  description: '创建新的配置',
  prompts: [
    {
      type: 'input',
      name: 'key',
      message: '输入新配置名称',
      validate: function(val) {
        return val !== ''
      }
    },
    {
      type: 'input',
      name: 'value',
      message: '输入新配置值',
      validate: function(val) {
        return val !== ''
      }
    }
  ],
  actions: function(data) {
    const { key, value } = data
    const setJson = require('../utils/setJson')
    const appendContent = require('../utils/appendContent')
    const fs = require('fs')
    const { resolve } = require('path')
    const clientConfigFix = resolve(__dirname, '../../src/config')
    const envItems = fs
      .readdirSync(clientConfigFix)
      .filter(item => item !== 'index.js')
      .map(item => {
        const env = item.split('.')[1]
        return {
          fileName: resolve(clientConfigFix, item),
          envPath: resolve(__dirname, '../../', `.env.${env}`),
          env
        }
      })
    envItems.forEach(item => {
      setJson(item.fileName, key, value)
      appendContent(item.envPath, key, value)
    })
    return []
  }
}
